<script Runat="Server" Language="JavaScript">
function Class_Core_Element_Structure_JSON(settings) {
	//Copyright (c) 2016 germar All rights reserved.
	//asp处理json通用类
	var compiler = function(code){
		var storage;
		if (/^[\[\{][\s\S]*[\]\}]$/.test(code)) {
			try {storage = (new Function("return " + code))()} catch (e) {}
		}
		return (typeof(storage) == "object") ? storage : (new Error(1002,"SyntaxError"));
	}
	var stringify = function(key, holder) {
		var gap, indent, rep, i, k, v, length, mind = gap, partial;
		var value = (key==null) ? holder : holder[key];
		switch (typeof value) {
		case 'string':
			return '"' + value + '"';
		case 'number':
			return isFinite(value) ? String(value) : 'null';
		case 'boolean':
		case 'null':
			return String(value);
		case 'object':
			gap += indent;
			partial = [];
			if (value instanceof Array) {
				length = value.length;
				for (i = 0; i < length; i += 1) {
					partial[i] = stringify(i, value) || 'null';
				}
				v = partial.length === 0 ? '[]': gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']': '[' + partial.join(',') + ']';
				gap = mind;
				return v;
			}
			if (rep && typeof rep === 'object') {
				length = rep.length;
				for (i = 0; i < length; i += 1) {
					if (typeof rep[i] === 'string') {
						k = rep[i];
						v = stringify(k, value);
						if (v) {
							partial.push('"' + k + '"' + (gap ? ': ': ':') + v);
						}
					}
				}
			} else {
				for (k in value) {
					if (Object.prototype.hasOwnProperty.call(value, k)) {
						v = stringify(k, value);
						if (v) {
							partial.push('"' + k + '"' + (gap ? ': ': ':') + v);
						}
					}
				}
			}
			v = partial.length === 0 ? '{}': gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}': '{' + partial.join(',') + '}';
			gap = mind;
			return v;
		}
	}
	var constructor = function(){
		var translator = function(expression){
			if (!/^[\.\[]/.test(expression)) {
				expression = ["['",expression,"']"].join("").replace(/^\[''\]$/, "");
			}
			return expression;
		}
		this.Adapter = null;
		this.select = function(expression){
			var contents = undefined;
			if (typeof(this.Adapter) == "object") {
				contents = (new Function("return this" + translator(expression))).call(this.Adapter);
			}
			var expandObject = function(data){
				var container = new constructor();
				container.Adapter = data;
				if (data instanceof Array) {
					expandArray(container);
				}
				return container;
			}
			var expandArray = function(struct){
				struct.length = function(){
					return struct.Adapter.length;
				};
				var method = ["concat","push","unshift","join","pop","shift","slice","splice"];
				var index = method.length;
				while (index--) {
					struct[method[index]] = function(index){
						return function(){
							var output = struct.Adapter[index].apply(struct.Adapter, arguments);
							if (typeof(output) == "object") {
								output = expandObject(output);
							}
							return output;
						};
					}(method[index]);
				}
				struct.item = function(index){
					var item = this.Adapter[index];
					if (typeof(item) == "object") {
						item = expandObject(item);
					}
					return item;
				}
			}
			if (typeof(contents) == "object") {
				contents = expandObject(contents);
			}
			return contents;
		}
		this.exist = function(expression){
			return !(this.select(expression) == undefined);
		}
		this.read = function(expression,default_){
			var contents = this.select(expression);
			if (contents == undefined) {
				contents = default_;
			}
			return contents;
		}
		this.edit = function(expression,contents){
			(new Function("value","this" + translator(expression) + "=value")).call(this.Adapter,contents);
		}
		this.keys = function(){
			var index = [];
			for (var i in this.Adapter) {
				if(this.Adapter.hasOwnProperty(i)){
					index.push(i);
				}
			};
			return index.join(',');
		}
		this.toString = function(){
			return stringify(null,this.Adapter);
		}
	}
	var container = new constructor();
	container.Adapter = compiler(settings);
	return container.select();
}
</script>